package com.example.site_management_p1.controller;
import com.example.site_management_p1.service.ISiteService;
import com.pojo.Entity.Site;
import com.pojo.Entity.VenueRentalForm;
import com.pojo.dto.ToDate;
import com.pojo.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@RequestMapping("site")
@RestController
public class SiteController {
    @Autowired
    ISiteService iSiteService;
    @GetMapping("/getlsite/{page}/{number}")
    public Result<?> getlsite(@PathVariable Integer page, @PathVariable Integer number){
            Result result=Result.success(iSiteService.getlsite(page,number));
            result.setMessage(String.valueOf(iSiteService.getsum()));
            return result;
    }
    @GetMapping("/getsite/{sID}")
    public Result<?>getsite(@PathVariable Integer sID){
        Site site=iSiteService.getsite(sID);
        return site==null?Result.failure():Result.success(site);
    }
    @PostMapping("/update")
    public Result<?>update( Site site, HttpServletRequest httpServletRequest){
        return iSiteService.update(site,httpServletRequest)==1?Result.success(1):Result.failure();
    }
    @PostMapping("/insert")
    public Result<?>insert( Site site, HttpServletRequest httpServletRequest){
        return iSiteService.insert(site,httpServletRequest)==1?Result.success(1):Result.failure();
    }
    @PostMapping("/presite")
    public Result<?>presite( String vBegintime,
                             String vEndtime,
                             String  vDate,
                             Integer sID,
                             HttpServletRequest httpServletRequest){
        VenueRentalForm venueRentalForm=iSiteService.presite(vBegintime,vEndtime,vDate,sID,httpServletRequest);
        return   venueRentalForm==null?Result.failure():Result.success(venueRentalForm);
    }
    @PostMapping("/cpresite")
    public Result<?>cpresite( String vBegintime,
                             String vEndtime,
                             String vDate,
                             Integer sID,
                             HttpServletRequest httpServletRequest){
        VenueRentalForm venueRentalForm=iSiteService.Cpresite(vBegintime,vEndtime,vDate,sID,httpServletRequest);
        return   venueRentalForm==null?Result.failure():Result.success(venueRentalForm);
    }
    @GetMapping("/getsdate/{vDate}/{sID}")
    public Result<?>getsdate(@PathVariable String vDate,@PathVariable Integer sID){
        List<ToDate> l=iSiteService.getdelsite(vDate,sID);
        System.out.println(l);
        return Result.success(l);
    }
    @PostMapping("/payment")
    public Result<?>payment( Integer vID, Integer vPaymentStatus){
        System.out.println(vID);
        return iSiteService.payment(vID,vPaymentStatus)==1?Result.success(1):Result.failure();
    }
    @PostMapping("getvr")
    public Result<?>getvr(HttpServletRequest httpServletRequest){
        return Result.success(iSiteService.getAftter(httpServletRequest));
    }
    @PostMapping("delete")
    public Result<?>delete(Integer sID,HttpServletRequest httpServletRequest){
        return  iSiteService.delete(sID)==1?Result.success(1):Result.failure();
    }
}
